package com.pandora.credit.mongo.dao.impl;

import com.pandora.credit.mongo.dao.MongoBannerDao;
import com.pandora.credit.mongo.entity.MongoBanner;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author developer
 */
@Repository("mongoBannerDaoImpl")
public class MongoBannerDaoImpl implements MongoBannerDao {
    @Resource
    private MongoTemplate mongoTemplatePc;

    @Override
    public List<MongoBanner> selectByTypeStatus(int type, int status) {
        Query query = new Query();
        Criteria criteria = Criteria.where("type").is(type).and("status").is(status);
        query.addCriteria(criteria);
        query.with(new Sort(Sort.Direction.DESC, "recommend"));
        List<MongoBanner> li = mongoTemplatePc.find(query, MongoBanner.class);
        return li;
    }
}
